﻿@{
    ViewBag.Title = "订单列表";
    string type = ViewBag.Type;
}
@using FwProject.ShoppingMall.Com
@section styles{
    <link href="~/static/css/client.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/system.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/contract.css" type="text/css" rel="stylesheet" />

}
<style>
    a {
        text-decoration: none;
    }

    .brand_logo {
        width: 28px;
        height: 28px;
    }

    .hidden {
        display: none;
    }

    .layui-upload-img {
        max-width: 300px;
        max-height: 200px;
    }
</style>
<div class="layui-fluid layui-content">
    <div class="layui-title layui-clear layui-row">
        <h2 class="layui-col-md10 layui-col-sm9 layui-col-xs7">@ViewBag.Title</h2>
        <div class="layui-col-md2 layui-col-sm3 layui-col-xs5 layui-nav-item" style="float:right;">
            <button type="button" class="layui-btn layui-btn-xs" onclick="Export()"><i class="layui-icon">&#xe63c;</i>导出</button>
        </div>
    </div>
    <div class="layui-eacher layui-row layui-clear">
        <form class="layui-clear">
            <div class="layui-form layui-clear">
                @if (type != "Receipt")
                {
                    <div class="layui-form-group layui-col-pc1 layui-col-md2 layui-col-sm4 layui-col-xs6">
                        <label class="layui-form-label">发货状态：</label>
                        <div class="layui-input-block">
                            <select name="DeliveryStatus" id="DeliveryStatus">
                                <option value=""></option>
                                <option value="未发货">未发货</option>
                                <option value="已发货">已发货</option>
                                <option value="已确认">已确认</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-group layui-col-pc1 layui-col-md2 layui-col-sm4 layui-col-xs6">
                        <label class="layui-form-label">支付状态：</label>
                        <div class="layui-input-block">
                            <select name="PayStatus" id="PayStatus">
                                <option value=""></option>
                                <option value="未支付">未支付</option>
                                <option value="已支付">已支付</option>
                                <option value="取消订单">取消订单</option>
                            </select>
                        </div>
                    </div>
                }
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <label class="layui-form-label">下单日期：</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="CreationTime" placeholder="下单日期" id="CreationTime" />
                    </div>
                </div>
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <label class="layui-form-label">
                        关键词：
                    </label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="keyword" placeholder="订单号" id="keyword" />
                    </div>
                </div>
                <div class="layui-col-md1">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" id="search" type="button"> 搜索 </button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-data layui-table-container">
        <table class="layui-hide layui-table" id="layui-table" lay-filter="table"></table>
    </div>
</div>
<div id="Layer_ajax" class="deploy-plus"></div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">订单明细</a>
    <a class="layui-btn layui-btn-xs" lay-event="operating">操作</a>
</script>
@section scripts{
    <script src="~/static/js/jquery.ztree.core.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.excheck.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.exedit.js" type="text/javascript"></script>
    <script src="~/js/main.js"></script>
    <script type="text/javascript">

        var layer,form, table, upload;
        layui.use(['form', 'layedit', 'laydate', 'tree', 'table', 'layer'], function () {
            var /*form = layui.form*/
                layedit = layui.layedit
                , laydate = layui.laydate;
            layer = layui.layer
            form = layui.form;
            table = layui.table;

            //日期时间范围
            laydate.render({
                elem: '#CreationTime'
                , type: 'date'
                , range: "~"
                , calendar: true
            });


            table.render({
                elem: "#layui-table",
                url: '@Url.Action("GetOrderData")',
                @if (!string.IsNullOrEmpty(type))
                 {
                    <text>
                where: {
                    ShopOrderStatus: "@type",
                },
                    </text>
                 }
                cellMinWidth: 26,
                height: 'full-150',
                cols: [[
                    //{ type: 'checkbox' },
                    { field: 'orderNumber', title: '订单号'},
                    {
                        field: 'creationTime', title: '下单日期', templet: function (d) {
                            var creationTime = new Date(d.creationTime);
                            return 'creationTime', top.dateFtt("yyyy-MM-dd hh:mm:ss", creationTime);
                    } },
                    { field: 'payTotal', title: '订单总额' },
                    { field: 'payAmount', title: '实付金额' },
                    {
                      field: 'deliveryStatus', title: '发货状态', templet: function (d) {
                            if (d.deliveryStatus == 0) {
                                return 'deliveryStatus', "未发货";
                            } else if (d.deliveryStatus == 1) {
                                return 'deliveryStatus', "已发货";
                            } else if (d.deliveryStatus == 2) {
                                return 'deliveryStatus', "已确认";
                            }

                    } },
                    {
                        field: 'shopReceivingAddress', title: '收货人',templet:function(d) {
                            return 'shopReceivingAddress', d.shopReceivingAddress.receivingName;
                        }
                    },
                    {
                        field: 'payStatus', title: '支付状态', templet: function (d) {
                            if(d.payStatus==0){
                                 return 'payStatus',"未支付";
                            } else if (d.payStatus ==1) {
                                 return 'payStatus',"已支付";
                            } else {
                                return 'payStatus', "取消订单";
                            }
                        }
                    },
                    {
                        field: 'payType', title: '支付方式', templet: function (d) {
                            if (d.payType == 0) {
                                return 'payType', "微信";
                            } else if (d.payType == 1) {
                                return 'payType', "支付宝";
                            }
                        }
                    },
                    { title: '操作', width: 213, align: 'center', toolbar: '#barDemo' }
                ]],
                id: "idTest",
                page: true,
            });

            //监听状态开关
            form.on('switch(checkbox)', function (data) {
                var id = data.value;
                var prompt = ""
                if (data.elem.checked) {
                    prompt = "供应商已开启！"
                } else {
                    prompt = "供应商已停用！"
                }

                $.get("/Supplier/SwitchActive?id=" + id + "&active=" + data.elem.checked, function (r) {
                    if (r.success) {
                        layer.msg(prompt, {
                            icon: 1,
                            time: 2000
                        });
                    } else {
                        layer.msg("操作失败", {
                            icon: 2,
                            time: 2000
                        });
                    }

                })
            });
            //监听工具条
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    LayerOpen("订单明细-" + data.orderNumber,"/Order/OrderDetail?id="+data.id)
                } else if (obj.event === 'operating') {
                    top.NewTab(data.orderNumber,"订单明细-" + data.orderNumber,"/Order/OrderHandle?id=" + data.id);
                }
            });
            $('#search').on('click', function () {
                table.reload('idTest', {
                    where: {
                        keyword: $('#keyword').val(),
                            @if (type != "Receipt")
                            {
                                <text>
                        DeliveryStatus: $('#DeliveryStatus').val(),
                        PayStatus: $('#PayStatus').val(),
                                </text>

                            }
                           
                        CreationTime: $('#CreationTime').val()
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            })



        });


        $("#layui-Area").click(function () {
            $(".layui-Area .layui-Area-hide").toggleClass("layui-Area-show")
            $(this).parent(".layui-form-select").toggleClass("layui-form-selected");
        });

        $(".layui-Area").mouseleave(function () {
            $(".layui-Area .layui-Area-hide").removeClass("layui-Area-show")
        })


        $(document).ready(function () {

        });
        var lock = false;//锁作为全局变量
        function LoadNewOpen(url) {
            if (lock) {
                return false;
            } else {
                lock = true;
            }
            $("#Layer_ajax").load(url, function (responseTxt, statusTxt, xhr) {
                if (statusTxt == "error") {
                    top.layer.msg('页面加载失败！', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }
                form.render('select')

                $.validator.unobtrusive.parse(this);
                var height = $("#Layer_ajax").height();
                layer.open({
                    type: 1,
                    shadeClose: true,
                    title: false,
                    closeBtn: 0,
                    scrollbar: false,
                    content: $("#Layer_ajax"),
                    area: ["600px", height],
                    success: function (layero, index) {
                        //锁关闭
                        lock = false;
                    },
                    end: function () {
                        $("#Layer_ajax").empty();
                    }
                })
            })
        }

        function LayerOpen(title, url) {
            var open = layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['700px', '520px'],
                content: url,
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index)//确定两个页面的父子关系
                },
                end: function () {
                    //销毁后重新加载
                    //table.reload('idTest', {
                    //    page: {
                    //        curr: 1 //重新从第 1 页开始
                    //    }
                    //})
                }
            });
        }

        function Export() {
            var keyword = $('#keyword').val();
                 @if (!string.IsNullOrEmpty(type))
                 {
                    <text>
                    window.location.href = "/Order/ExportOrderData?keyword=" + keyword+"&status=@type";
                    </text>
                 }
                 else
                 {
                    <text>
                    window.location.href = "/Order/ExportOrderData?keyword=" + keyword;
                    </text>
                 }


        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            }, successInfo)
        }


                    //$(".layui-content").on("click", ".layer-load-new", function () {

                    //});
    </script>
}